
function buffIcon()
    BUFF_DISPLAY_KEYS = {}
    --buff图标
    BUFF_ICON = {
        --以下全是附魔相关图标，没弄
        e_physical_attack = "buffIcon\\buff_e_physical_attack.tga",
        e_magic_attack = "buffIcon\\buff_reborn.tga",
        e_fire_attack = "buffIcon\\buff_reborn.tga",
        e_flame_attack = "buffIcon\\buff_reborn.tga",
        e_soil_attack = "buffIcon\\buff_reborn.tga",
        e_rock_attack = "buffIcon\\buff_reborn.tga",
        e_sand_attack = "buffIcon\\buff_reborn.tga",
        e_lava_attack = "buffIcon\\buff_reborn.tga",
        e_water_attack = "buffIcon\\buff_reborn.tga",
        e_ice_attack = "buffIcon\\buff_reborn.tga",
        e_storm_attack = "buffIcon\\buff_reborn.tga",
        e_wind_attack = "buffIcon\\buff_reborn.tga",
        e_light_attack = "buffIcon\\buff_reborn.tga",
        e_dark_attack = "buffIcon\\buff_reborn.tga",
        e_wood_attack = "buffIcon\\buff_reborn.tga",
        e_grass_attack = "buffIcon\\buff_reborn.tga",
        e_thunder_attack = "buffIcon\\buff_reborn.tga",
        e_electric_attack = "buffIcon\\buff_reborn.tga",
        e_metal_attack = "buffIcon\\buff_reborn.tga",
        e_iron_attack = "buffIcon\\buff_reborn.tga",
        e_steel_attack = "buffIcon\\buff_reborn.tga",
        e_dragon_attack = "buffIcon\\buff_reborn.tga",
        e_insect_attack = "buffIcon\\buff_reborn.tga",
        e_poison_attack = "buffIcon\\buff_reborn.tga",
        e_evil_attack = "buffIcon\\buff_reborn.tga",
        e_ghost_attack = "buffIcon\\buff_reborn.tga",
        e_god_attack = "buffIcon\\buff_reborn.tga",
        e_holy_attack = "buffIcon\\buff_reborn.tga",
        e_physical_append = "buffIcon\\buff_reborn.tga",
        e_magic_append = "buffIcon\\buff_reborn.tga",
        e_fire_append = "buffIcon\\buff_reborn.tga",
        e_flame_append = "buffIcon\\buff_reborn.tga",
        e_soil_append = "buffIcon\\buff_reborn.tga",
        e_rock_append = "buffIcon\\buff_reborn.tga",
        e_sand_append = "buffIcon\\buff_reborn.tga",
        e_lava_append = "buffIcon\\buff_reborn.tga",
        e_water_append = "buffIcon\\buff_reborn.tga",
        e_ice_append = "buffIcon\\buff_reborn.tga",
        e_storm_append = "buffIcon\\buff_reborn.tga",
        e_light_append = "buffIcon\\buff_reborn.tga",
        e_dark_append = "buffIcon\\buff_reborn.tga",
        e_wood_append = "buffIcon\\buff_reborn.tga",
        e_grass_append = "buffIcon\\buff_reborn.tga",
        e_thunder_append = "buffIcon\\buff_reborn.tga",
        e_electric_append = "buffIcon\\buff_reborn.tga",
        e_metal_append = "buffIcon\\buff_reborn.tga",
        e_iron_append = "buffIcon\\buff_reborn.tga",
        e_steel_append = "buffIcon\\buff_reborn.tga",
        e_dragon_append = "buffIcon\\buff_reborn.tga",
        e_insect_append = "buffIcon\\buff_reborn.tga",
        e_poison_append = "buffIcon\\buff_reborn.tga",
        e_evil_append = "buffIcon\\buff_reborn.tga",
        e_ghost_append = "buffIcon\\buff_reborn.tga",
        e_god_append = "buffIcon\\buff_reborn.tga",
        e_holy_append = "buffIcon\\buff_reborn.tga",
        e_physical = "buffIcon\\buff_reborn.tga",
        e_physical_oppose = "buffIcon\\buff_reborn.tga",
        e_magic = "buffIcon\\buff_reborn.tga",
        e_magic_oppose = "buffIcon\\buff_reborn.tga",
        e_fire = "buffIcon\\buff_reborn.tga",
        e_fire_oppose = "buffIcon\\buff_reborn.tga",
        e_flame = "buffIcon\\buff_reborn.tga",
        e_flame_oppose = "buffIcon\\buff_reborn.tga",
        e_soil = "buffIcon\\buff_reborn.tga",
        e_soil_oppose = "buffIcon\\buff_reborn.tga",
        e_rock = "buffIcon\\buff_reborn.tga",
        e_rock_oppose = "buffIcon\\buff_reborn.tga",
        e_sand = "buffIcon\\buff_reborn.tga",
        e_sand_oppose = "buffIcon\\buff_reborn.tga",
        e_lava = "buffIcon\\buff_reborn.tga",
        e_lava_oppose = "buffIcon\\buff_reborn.tga",
        e_water = "buffIcon\\buff_reborn.tga",
        e_water_oppose = "buffIcon\\buff_reborn.tga",
        e_ice = "buffIcon\\buff_reborn.tga",
        e_ice_oppose = "buffIcon\\buff_reborn.tga",
        e_storm = "buffIcon\\buff_reborn.tga",
        e_storm_oppose = "buffIcon\\buff_reborn.tga",
        e_wind = "buffIcon\\buff_reborn.tga",
        e_wind_oppose = "buffIcon\\buff_reborn.tga",
        e_light = "buffIcon\\buff_reborn.tga",
        e_light_oppose = "buffIcon\\buff_reborn.tga",
        e_dark = "buffIcon\\buff_reborn.tga",
        e_dark_oppose = "buffIcon\\buff_reborn.tga",
        e_wood = "buffIcon\\buff_reborn.tga",
        e_wood_oppose = "buffIcon\\buff_reborn.tga",
        e_grass = "buffIcon\\buff_reborn.tga",
        e_grass_oppose = "buffIcon\\buff_reborn.tga",
        e_thunder = "buffIcon\\buff_reborn.tga",
        e_thunder_oppose = "buffIcon\\buff_reborn.tga",
        e_electric = "buffIcon\\buff_reborn.tga",
        e_electric_oppose = "buffIcon\\buff_reborn.tga",
        e_metal = "buffIcon\\buff_reborn.tga",
        e_metal_oppose = "buffIcon\\buff_reborn.tga",
        e_iron = "buffIcon\\buff_reborn.tga",
        e_iron_oppose = "buffIcon\\buff_reborn.tga",
        e_steel = "buffIcon\\buff_reborn.tga",
        e_steel_oppose = "buffIcon\\buff_reborn.tga",
        e_dragon = "buffIcon\\buff_reborn.tga",
        e_dragon_oppose = "buffIcon\\buff_reborn.tga",
        e_insect = "buffIcon\\buff_reborn.tga",
        e_insect_oppose = "buffIcon\\buff_reborn.tga",
        e_poison = "buffIcon\\buff_reborn.tga",
        e_poison_oppose = "buffIcon\\buff_reborn.tga",
        e_evil = "buffIcon\\buff_reborn.tga",
        e_evil_oppose = "buffIcon\\buff_reborn.tga",
        e_ghost = "buffIcon\\buff_reborn.tga",
        e_ghost_oppose = "buffIcon\\buff_reborn.tga",
        e_god = "buffIcon\\buff_reborn.tga",
        e_god_oppose = "buffIcon\\buff_reborn.tga",
        e_holy = "buffIcon\\buff_reborn.tga",
        e_holy_oppose = "buffIcon\\buff_reborn.tga",
        --以上全是附魔相关图标，没弄


        reborn = "buffIcon\\buff_reborn.tga",
        attack_speed = "buffIcon\\buff_attack_speed.tga",
        attack_space = "buffIcon\\buff_attack_speed.tga",
        attack_space_origin = "buffIcon\\buff_attack_speed.tga",
        attack = "buffIcon\\buff_attack.tga",
        attack_white = "buffIcon\\buff_attack.tga",
        attack_green = "buffIcon\\buff_attack.tga",
        attack_range_acquire = "buffIcon\\buff_attack_range_acquire.tga",
        attack_range = "buffIcon\\buff_attack_range_acquire.tga",
        defend = "buffIcon\\buff_defend.tga",
        defend_white = "buffIcon\\buff_defend.tga",
        defend_green = "buffIcon\\buff_defend.tga",
        str = "buffIcon\\buff_str.tga",
        agi = "buffIcon\\buff_agi.tga",
        int = "buffIcon\\buff_int.tga",
        str_green = "buffIcon\\buff_str.tga",
        agi_green = "buffIcon\\buff_agi.tga",
        int_green = "buffIcon\\buff_int.tga",
        str_white = "buffIcon\\buff_str.tga",
        agi_white = "buffIcon\\buff_agi.tga",
        int_white = "buffIcon\\buff_int.tga",
        life = "buffIcon\\buff_life.tga",
        mana = "buffIcon\\buff_mana.tga",
        life_back = "buffIcon\\buff_life_back.tga",
        mana_back = "buffIcon\\buff_mana_back.tga",
        move = "buffIcon\\buff_move.tga",
        sight = "buffIcon\\buff_sight.tga",
        avoid = "buffIcon\\buff_avoid.tga",
        aim = "buffIcon\\buff_aim.tga",
        punish = "buffIcon\\buff_punish.tga",
        punish_current = "buffIcon\\buff_punish.tga",
        hemophagia = "buffIcon\\buff_hemophagia.tga",
        hemophagia_skill = "buffIcon\\buff_hemophagia.tga",
        siphon = "buffIcon\\buff_siphon.tga",
        siphon_skill = "buffIcon\\buff_siphon.tga",
        invincible = "buffIcon\\buff_invincible.tga",
        weight = "buffIcon\\buff_weight.tga",
        weight_current = "buffIcon\\buff_weight.tga",
        damage_extent = "buffIcon\\buff_damage_extent.tga",
        damage_reduction = "buffIcon\\buff_damage_reduction.tga",
        damage_decrease = "buffIcon\\buff_damage_reduction.tga",
        damage_rebound = "buffIcon\\buff_damage_rebound.tga",
        damage_rebound_oppose = "buffIcon\\buff_damage_rebound.tga",
        cure = "buffIcon\\buff_cure.tga",
        knocking_odds = "buffIcon\\buff_knocking_odds.tga",
        knocking_extent = "buffIcon\\buff_knocking_extent.tga",
        knocking_oppose = "buffIcon\\buff_knocking_oppose.tga",
        hemophagia_oppose = "buffIcon\\buff_hemophagia_oppose.tga",
        hemophagia_skill_oppose = "buffIcon\\buff_hemophagia_oppose.tga",
        siphon_oppose = "buffIcon\\buff_hemophagia_oppose.tga",
        siphon_skill_oppose = "buffIcon\\buff_hemophagia_oppose.tga",
        split_oppose = "buffIcon\\buff_split_oppose.tga",
        punish_oppose = "buffIcon\\buff_punish_oppose.tga",
        swim_oppose = "buffIcon\\buff_swim_oppose.tga",
        broken_oppose = "buffIcon\\buff_broken_oppose.tga",
        silent_oppose = "buffIcon\\buff_silent_oppose.tga",
        unarm_oppose = "buffIcon\\buff_unarm_oppose.tga",
        fetter_oppose = "buffIcon\\buff_fetter_oppose.tga",
        bomb_oppose = "buffIcon\\buff_bomb_oppose.tga",
        lightning_chain_oppose = "buffIcon\\buff_lightning_chain_oppose.tga",
        crack_fly_oppose = "buffIcon\\buff_crack_fly_oppose.tga",
        xtras = "ReplaceableTextures\\PassiveButtons\\PASBTNBash.blp",
        gold_ratio = "buffIcon\\buff_gold_ratio.tga",
        lumber_ratio = "buffIcon\\buff_lumber_ratio.tga",
        exp_ratio = "buffIcon\\buff_exp_ratio.tga",
        sell_ratio = "buffIcon\\buff_sell_ratio.tga",
    }
    for _, k in ipairs(CONST_ATTR_KEYS) do
        table.insert(BUFF_DISPLAY_KEYS, { name = CONST_ATTR_LABEL[k], icon = BUFF_ICON[k] })
    end
end

function buffUI()
    hdzui.loadToc("UI\\frame.toc")
    buffIcon()

    selectedUnit = {}
    hplayer.forEach(function(enumPlayer, idx)
        hevent.onSelection(enumPlayer,1,function(evtData)
            selectedUnit[idx] = evtData.triggerUnit
        end)
    end)


    local playerTxt = {}
    playerTxt[hplayer.index(hplayer.players[1])] = {}
    hplayer.forEach(
        function(enumPlayer, idx)
            if (his.playing(enumPlayer)) then
                playerTxt[idx] = {}
            end
        end
    )

    local tip = {}
    tip[1] = hdzui.frameTag("BACKDROP", "exp_kk", hdzui.origin.game())

    tip[2] = hdzui.frameTag("TEXT", "txt_10l", tip[1])
    hjapi.DzFrameSetSize(tip[2], 0.16, 0)
    hjapi.DzFrameSetPoint(tip[1], 0, tip[2], 0, -0.005, 0.005)
    hjapi.DzFrameSetPoint(tip[1], 8, tip[2], 8, 0.005, -0.005)
    --hdzui.framePoint(tip[2], demoCache.itemSlot[1], FRAME_ALIGN_LEFT_BOTTOM, FRAME_ALIGN_LEFT_TOP, -0.002, 0.02)
    hjapi.DzFrameShow(tip[1], false)

    local tipTxt = function()
        local fm = hjapi.DzGetTriggerUIEventFrame()
        local idx = hplayer.index(hjapi.DzGetTriggerUIEventPlayer())
        hjapi.DzFrameSetText(tip[2], playerTxt[idx][fm])
        hdzui.framePoint(tip[2], fm, FRAME_ALIGN_LEFT_BOTTOM, FRAME_ALIGN_RIGHT_TOP, -0.01, 0.01)
        hjapi.DzFrameShow(tip[1], true)
    end
    local tipTxtNo = function()
        hjapi.DzFrameShow(tip[1], false)
    end

    SINGLUAR_UI_ABILITY_MAX = 11 * 2 --最大buff数,偶数

    local bagRx = 0.016
    local bagRy = bagRx * (8 / 6)

    local SLBuffBtns = {}
    local SLBuffTxt = {}
    local SLBuffExts = {}
    local SLBuffBorders = {}

    for i = 1, SINGLUAR_UI_ABILITY_MAX do
        local x = -0.084 + bagRx * (i - 1)
        local y = 0.142
        local half = SINGLUAR_UI_ABILITY_MAX / 2
        if (i > half) then
            x = -0.084 + bagRx * (i - half - 1)
            y = 0.142 + bagRy
        end

        --buff图标
        SLBuffExts[i] = hdzui.frameTag("BACKDROP", "sdk_buff->ext->" .. i, hdzui.origin.game(), "")
        hjapi.DzFrameSetPoint(SLBuffExts[i], 7, hdzui.origin.game(), 7, x, y)
        hjapi.DzFrameSetSize(SLBuffExts[i], bagRx, bagRy)
        hjapi.DzFrameShow(SLBuffExts[i], false)

        --三角图标
        SLBuffBorders[i] = hdzui.frameTag("BACKDROP", "sdk_buff->border->" .. i, SLBuffExts[i], "")
        hjapi.DzFrameSetPoint(SLBuffBorders[i], 4, SLBuffExts[i], 4, 0, 0)
        hjapi.DzFrameSetSize(SLBuffBorders[i], bagRx, bagRy)
        hjapi.DzFrameShow(SLBuffBorders[i], true)

        --时间文本
        SLBuffTxt[i] = hdzui.frameTag("TEXT", "T666", SLBuffExts[i])
        hjapi.DzFrameSetText(SLBuffTxt[i], "")
        hjapi.DzFrameSetPoint(SLBuffTxt[i], 4, SLBuffExts[i], 4, 0, 0)
        hjapi.DzFrameShow(SLBuffTxt[i], true)

        --按钮
        SLBuffBtns[i] = hdzui.frameTag("BUTTON", "sdk_buff->btn->" .. i, SLBuffExts[i], nil)
        hjapi.DzFrameSetPoint(SLBuffBtns[i], 4, SLBuffExts[i], 4, 0, 0)
        hjapi.DzFrameSetSize(SLBuffBtns[i], bagRx, bagRy)
        hjapi.DzFrameShow(SLBuffBtns[i], true)

        --进入按钮动作

        hdzui.onMouse(SLBuffBtns[i], 2, tipTxt)
        hdzui.onMouse(SLBuffBtns[i], 3, tipTxtNo)
        --
    end

    htime.setInterval(
        0.1,
        function(_)
            hplayer.forEach(
                function(enumPlayer, idx)
                    local selection = selectedUnit[idx]
                    local show = false
                    local showIdx = {}
                    if (his.playing(enumPlayer) and selection ~= nil) then
                        if (his.alive(selection)) then
                            local buffHandle = hcache.get(selection, CONST_CACHE.BUFF)
                            if (buffHandle ~= nil) then
                                show = true
                                local buffTab = {}
                                local sort = {}
                                for bi, b in ipairs(CONST_ATTR_KEYS) do
                                    local keys = ""
                                    local symbol = ""
                                    if (buffHandle["attr." .. b .. "+"] ~= nil) then
                                        keys = "attr." .. b .. "+"
                                        symbol = "+"
                                        for _, buffKey in ipairs(buffHandle[keys]._idx) do
                                            buffHandle[keys][buffKey].num = bi
                                            buffHandle[keys][buffKey].symbol = symbol
                                            buffTab[buffKey] = buffHandle[keys][buffKey]
                                            local s = {key = buffKey}
                                            table.insert(sort, s)
                                        end
                                    end
                                    if (buffHandle["attr." .. b .. "-"] ~= nil) then
                                        keys = "attr." .. b .. "-"
                                        symbol = "-"
                                        for _, buffKey in ipairs(buffHandle[keys]._idx) do
                                            buffHandle[keys][buffKey].num = bi
                                            buffHandle[keys][buffKey].symbol = symbol
                                            buffTab[buffKey] = buffHandle[keys][buffKey]
                                            local s = {key = buffKey}
                                            table.insert(sort, s)
                                        end
                                    end
                                end
                                ----
                                --排序
                                table.sort(
                                    sort,
                                    function(a, b)
                                        return a.key < b.key
                                    end
                                )

                                if (show) then
                                    for idxs, v in ipairs(sort) do
                                        if (idxs < SINGLUAR_UI_ABILITY_MAX) then
                                            showIdx[idxs] = true
                                            local time = buffTab[v.key].times
                                            local bi = buffTab[v.key].num
                                            local icon = BUFF_DISPLAY_KEYS[bi].icon
                                            local name = BUFF_DISPLAY_KEYS[bi].name
                                            local t = math.round(time.remain(), 1)
                                            local difference = 0
                                            local icoTga = ""
                                            if (buffTab[v.key].symbol == "+") then
                                                icoTga = "buffIcon\\up.tga"
                                                difference =
                                                    hcolor.green(buffTab[v.key].symbol .. buffTab[v.key].difference)
                                            else
                                                icoTga = "buffIcon\\down.tga"
                                                difference = hcolor.red(buffTab[v.key].difference)
                                            end
                                            --提示框 需要，没做 自己弄
                                            playerTxt[idx][SLBuffBtns[idxs]] =
                                                name ..
                                                ":" .. difference .. "|n" .. hcolor.greenLight("持续:" .. t .. "秒")
                                            if (enumPlayer == hplayer.loc()) then
                                                hjapi.DzFrameSetTexture(SLBuffBorders[idxs], icoTga, false)
                                                hjapi.DzFrameSetText(SLBuffTxt[idxs], t)
                                                hjapi.DzFrameSetTexture(SLBuffExts[idxs], icon, false)
                                                if (t <= 3) then
                                                    local transparency = 50 + 255 * t / 3
                                                    hjapi.DzFrameSetAlpha(SLBuffTxt[idxs], transparency)
                                                    hjapi.DzFrameSetAlpha(SLBuffExts[idxs], transparency)
                                                    hjapi.DzFrameSetAlpha(SLBuffBorders[idxs], transparency)
                                                else
                                                    hjapi.DzFrameSetAlpha(SLBuffTxt[idxs], 255)
                                                    hjapi.DzFrameSetAlpha(SLBuffExts[idxs], 255)
                                                    hjapi.DzFrameSetAlpha(SLBuffBorders[idxs], 255)
                                                end
                                            end
                                        end
                                    end
                                end
                            end
                        end
                    end
                    for k, _ in ipairs(SLBuffBtns) do
                        if (enumPlayer == hplayer.loc()) then
                            if (show and showIdx[k] == true) then
                                hjapi.DzFrameShow(SLBuffExts[k], true)
                            else
                                hjapi.DzFrameShow(SLBuffExts[k], false)
                            end
                        end
                    end
                end
            )
        end
    )
end
